/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package client;

import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import server.Cpu;
import server.Memoire;
import server.Monitor;
import server.Processus;

/**
 *
 * @author juge-e
 */
@XmlRootElement
public class MonitorClient {

    private Monitor monMonitor;
    /**
     * Initialise le client avec un nom de serveur
     *
     * @param NomServeur
     */
    public void initialiser(String nomServeur) throws NotBoundException, MalformedURLException, RemoteException {
        monMonitor = (Monitor) Naming.lookup("//" + nomServeur + "/Monitor");
    }

    public Memoire getMemory() throws RemoteException {
        Memoire retour = null;
        if (null != monMonitor) {
            retour = monMonitor.getMemory();
        }
        return retour;

    }
    
    @XmlElement
    public ArrayList<String> getXmlMemory() throws RemoteException {
        Memoire mem = new Memoire();
        mem = getMemory();
        ArrayList<String> temp = new ArrayList<String>();
        temp.add(mem.getFree());
        temp.add(mem.getUsed());
        temp.add(mem.getTotal());
        return temp;

    }

    @XmlElement
        public String getXmlCpu() throws RemoteException {
        Cpu cpu = getCpu();
        if(cpu==null)
            return "";
        return cpu.getCpu();

    }
        
    public Cpu getCpu() throws RemoteException {
        Cpu retour = null;
        if (null != monMonitor) {
            retour = monMonitor.getCpu();
        }
        return retour;

    }

    @XmlElement
    public List<String> getXmlProcessus() throws RemoteException {
        return getProcessus().getProcess();
    }
    
    
    public Processus getProcessus() throws RemoteException {
        Processus retour = null;
        if (null != monMonitor) {
            retour = monMonitor.getProcessus();
        }
        return retour;
    }

}
